define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        app = require("dist/application/app"),
        config = app.config;
        var tip = require("./tip");
    exports.init = function(form) {
        if (form.hasClass('form-wizard-step')) {
            require.async(['jquery_ui', 'wizard', 'jform'], function() {
                form.formwizard({
                    validationEnabled: !0,
                    formPluginEnabled: !0,
                    focusFirstInput: !0,
                    disableUIStyles: false,
                    validationOptions: {

                    },
                    formOptions: {
                        dataType: 'json',
                        success: function(d) {
                             tip.run(d);
                        },
                        beforeSubmit: function(d) {
                            var f = true;
                            if ($('[data-toggle="selectimg"]', form).length > 0) {
                                $('[data-toggle="selectimg"]', form).each(function() {
                                    var $this = $(this),
                                        $input = $this.prev("input[type='text']"),
                                        validate = $input.data("ruleRequired"),
                                        msg = $input.data("msg") || "请上传图片";
                                    if (validate && !$input.val() && !$this.is(":hidden")) {
                                        config.msg.error(msg);
                                        f = false;
                                    }
                                });
                            }
                            if ($('[data-toggle="kindeditor"]', form).length > 0) {
                                if (typeof KindEditor !== "undefined" && KindEditor.instances) {
                                    $.each(KindEditor.instances, function() {
                                        this.sync();
                                        var $element = $(this.srcElement[0]);
                                        var r = $element.data("ruleRequired"),
                                            m = $element.data("msgRequired"),
                                            e = $element.data("ruleRangelength"),
                                            em = $element.data("msgRangelength"),
                                            hidden = $(this).is(":hidden");
                                        var v = $.trim($element.val()).replace(/(&nbsp;)|\s|\u00a0/g, '');

                                        if (r && !hidden) {
                                            if (v.length == 0) {
                                                var msg = m;
                                                config.msg.error(msg || "内容不能为空")
                                                f = false;
                                                return false
                                            }
                                        };
                                        if (e && !hidden) {
                                            var min = e[0];
                                            var max = e[1];
                                            var vv = $element.val();
                                            var len=this.count('text');
                                            if (len< min || len> max) {
                                                config.msg.error(em || "内容不能小于{0}且大于{1}".format(min, max))
                                                f = false;
                                                return false
                                            }
                                        }
                                    })
                                }
                            };
                            if($("form.design-form-special").length){
                                var $js_link_type_system= $(".blockitem .js_link_type_system",form);
                                $js_link_type_system.each(function(){
                                    if(!$(this).is(":hidden")){
                                        if($(".line-name-show",$(this)).html()==""){
                                            config.msg.error("请选择导航链接");
                                            f = false;
                                            return false;
                                        }
                                    }
                                });
                            }
                            if ($('[data-wizard-limit]', form).length > 0) {
                                $('[data-wizard-limit]', form).each(function() {
                                    var $this = $(this),
                                        type = $this.data("wizardLimit"),
                                        target = $this.data("target"),
                                        len = $(target, $this).length,
                                        msg = $this.data("msg");
                                    if (!$this.is(":hidden")) {
                                        if (type == "odd") {
                                            if (len % 2 == 0) {
                                                config.msg.error(msg);
                                                f = false;
                                            }
                                        } else if (type == "even") {

                                        } else {

                                        }
                                    }

                                });
                            }
                            return f;
                        },
                        error: function(d) {
                            config.msg.info(d.responseText)
                        }

                    }
                });

            })
        }
    }

})